# -*- coding: utf-8 -*-


import os
import uuid
import django
from datetime import datetime
from core.initialize import Initialize
from apps.sys.models import User, Post, Menu, DictType, DictData, Dept, Role, Config

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "application.settings")
django.setup()


class Init(Initialize):
    test_dept_id = uuid.uuid4()
    superadmin_role_id = uuid.uuid4()

    def init_dict(self):
        dict_type = [
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "id": uuid.uuid4(),
                "name": "系统启用",
                "type": "sys_enable_disable",
                "remark": "系统启用类型",
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "id": uuid.uuid4(),
                "name": "系统结果",
                "type": "sys_success_fail",
                "remark": "系统结果类型",
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "id": uuid.uuid4(),
                "name": "系统是否",
                "type": "sys_yes_no",
                "remark": "系统是否列表",
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "id": uuid.uuid4(),
                "name": "用户性别",
                "type": "sys_user_sex",
                "remark": "用户性别列表",
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "id": uuid.uuid4(),
                "name": "菜单状态",
                "type": "sys_show_hide",
                "remark": "菜单显示与隐藏状态列表",
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "id": uuid.uuid4(),
                "name": "优先级",
                "type": "sys_priority_level",
                "remark": "系统优先级列表",
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "id": uuid.uuid4(),
                "name": "严重性",
                "type": "sys_gravity_level",
                "remark": "系统严重性列表",
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "id": uuid.uuid4(),
                "name": "通知类型",
                "type": "sys_notice_type",
                "remark": "系统通知类型列表",
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "id": uuid.uuid4(),
                "name": "系统任务状态",
                "type": "sys_job_status",
                "remark": "系统任务类型列表",
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "id": uuid.uuid4(),
                "name": "系统HTTP请求类型",
                "type": "sys_http_method",
                "remark": "",
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "id": uuid.uuid4(),
                "name": "系统状态",
                "type": "sys_normal_abnormal",
                "remark": "系统状态类型",
            },
        ]
        dict_data = [
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "default": True,
                "id": uuid.uuid4(),
                "type": "sys_enable_disable",
                "sort": 1,
                "label": "启用",
                "value": "0",
                "tagType": "primary",
                "tagClass": "",
                "remark": "",
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "default": True,
                "id": uuid.uuid4(),
                "type": "sys_enable_disable",
                "sort": 2,
                "label": "停用",
                "value": "1",
                "tagType": "danger",
                "tagClass": "",
                "remark": "",
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "default": True,
                "id": uuid.uuid4(),
                "type": "sys_success_fail",
                "sort": 1,
                "label": "成功",
                "value": "0",
                "tagType": "primary",
                "tagClass": "",
                "remark": "",
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "default": True,
                "id": uuid.uuid4(),
                "type": "sys_success_fail",
                "sort": 2,
                "label": "失败",
                "value": "1",
                "tagType": "danger",
                "tagClass": "",
                "remark": "",
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "default": True,
                "id": uuid.uuid4(),
                "type": "sys_yes_no",
                "sort": 1,
                "label": "是",
                "value": "Y",
                "tagType": "primary",
                "tagClass": "",
                "remark": "系统默认是",
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "default": True,
                "id": uuid.uuid4(),
                "type": "sys_yes_no",
                "sort": 2,
                "label": "否",
                "value": "N",
                "tagType": "danger",
                "tagClass": "",
                "remark": "",
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "default": True,
                "id": uuid.uuid4(),
                "type": "sys_user_sex",
                "sort": 1,
                "label": "男",
                "value": "0",
                "tagType": "default",
                "tagClass": "",
                "remark": "",
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "default": True,
                "id": uuid.uuid4(),
                "type": "sys_user_sex",
                "sort": 2,
                "label": "女",
                "value": "1",
                "tagType": "default",
                "tagClass": "",
                "remark": "",
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "default": True,
                "id": uuid.uuid4(),
                "type": "sys_show_hide",
                "sort": 1,
                "label": "显示",
                "value": "0",
                "tagType": "primary",
                "tagClass": "",
                "remark": "",
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "default": True,
                "id": uuid.uuid4(),
                "type": "sys_show_hide",
                "sort": 2,
                "label": "隐藏",
                "value": "1",
                "tagType": "danger",
                "tagClass": "",
                "remark": "",
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "default": True,
                "id": uuid.uuid4(),
                "type": "sys_priority_level",
                "sort": 1,
                "label": "低",
                "value": "0",
                "tagType": "primary",
                "tagClass": "",
                "remark": "",
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "default": True,
                "id": uuid.uuid4(),
                "type": "sys_priority_level",
                "sort": 2,
                "label": "中",
                "value": "1",
                "tagType": "warning",
                "tagClass": "",
                "remark": "",
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "default": True,
                "id": uuid.uuid4(),
                "type": "sys_priority_level",
                "sort": 3,
                "label": "高",
                "value": "2",
                "tagType": "danger",
                "tagClass": "",
                "remark": "",
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "default": True,
                "id": uuid.uuid4(),
                "type": "sys_gravity_level",
                "sort": 1,
                "label": "提示",
                "value": "0",
                "tagType": "default",
                "tagClass": "",
                "remark": "",
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "default": True,
                "id": uuid.uuid4(),
                "type": "sys_gravity_level",
                "sort": 2,
                "label": "一般",
                "value": "1",
                "tagType": "primary",
                "tagClass": "",
                "remark": "",
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "default": True,
                "id": uuid.uuid4(),
                "type": "sys_gravity_level",
                "sort": 3,
                "label": "严重",
                "value": "2",
                "tagType": "warning",
                "tagClass": "",
                "remark": "",
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "default": True,
                "id": uuid.uuid4(),
                "type": "sys_gravity_level",
                "sort": 4,
                "label": "致命",
                "value": "3",
                "tagType": "danger",
                "tagClass": "",
                "remark": "",
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "default": True,
                "id": uuid.uuid4(),
                "type": "sys_notice_type",
                "sort": 1,
                "label": "通知",
                "value": "0",
                "tagType": "warning",
                "tagClass": "",
                "remark": "",
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "default": True,
                "id": uuid.uuid4(),
                "type": "sys_notice_type",
                "sort": 2,
                "label": "公告",
                "value": "1",
                "tagType": "success",
                "tagClass": "",
                "remark": "",
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "default": True,
                "id": uuid.uuid4(),
                "type": "sys_http_method",
                "sort": 1,
                "label": "GET",
                "value": "GET",
                "tagType": "primary",
                "tagClass": "",
                "remark": "",
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "default": True,
                "id": uuid.uuid4(),
                "type": "sys_http_method",
                "sort": 2,
                "label": "POST",
                "value": "POST",
                "tagType": "primary",
                "tagClass": "",
                "remark": "",
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "default": True,
                "id": uuid.uuid4(),
                "type": "sys_http_method",
                "sort": 3,
                "label": "PUT",
                "value": "PUT",
                "tagType": "warning",
                "tagClass": "",
                "remark": "",
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "default": True,
                "id": uuid.uuid4(),
                "type": "sys_http_method",
                "sort": 4,
                "label": "PATCH ",
                "value": "PATCH",
                "tagType": "primary",
                "tagClass": "",
                "remark": "",
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "default": True,
                "id": uuid.uuid4(),
                "type": "sys_http_method",
                "sort": 5,
                "label": "DELETE",
                "value": "DELETE",
                "tagType": "danger",
                "tagClass": "",
                "remark": "",
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "default": True,
                "id": uuid.uuid4(),
                "type": "sys_job_status",
                "sort": 1,
                "label": "未执行",
                "value": "0",
                "tagType": "primary",
                "tagClass": "",
                "remark": "",
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "default": True,
                "id": uuid.uuid4(),
                "type": "sys_job_status",
                "sort": 2,
                "label": "执行中",
                "value": "1",
                "tagType": "info",
                "tagClass": "",
                "remark": "",
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "default": True,
                "id": uuid.uuid4(),
                "type": "sys_job_status",
                "sort": 3,
                "label": "已完成",
                "value": "2",
                "tagType": "success",
                "tagClass": "",
                "remark": "",
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "default": True,
                "id": uuid.uuid4(),
                "type": "sys_normal_abnormal",
                "sort": 1,
                "label": "正常",
                "value": "0",
                "tagType": "success",
                "tagClass": "",
                "remark": "",
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "default": True,
                "id": uuid.uuid4(),
                "type": "sys_normal_abnormal",
                "sort": 2,
                "label": "故障",
                "value": "1",
                "tagType": "danger",
                "tagClass": "",
                "remark": "",
            },
        ]
        self.save(DictType, dict_type, "字典类型")
        self.save(DictData, dict_data, "字典数据")

    def init_dept(self):
        """
        初始化部门信息
        """
        self.dept_data = [
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "id": self.dept_belong_id,
                "name": "研发部门",
                "owner": "",
                "phone": "",
                "parent_id": None,
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "id": uuid.uuid4(),
                "name": "测试部门",
                "owner": "",
                "phone": "",
                "parent_id": self.dept_belong_id,
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "id": uuid.uuid4(),
                "name": "运维部门",
                "owner": "",
                "phone": "",
                "parent_id": self.dept_belong_id,
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "id": uuid.uuid4(),
                "name": "开发一部",
                "owner": "",
                "phone": "",
                "parent_id": self.dept_belong_id,
            },
        ]
        self.save(Dept, self.dept_data, "部门信息")

    def init_post(self):
        """
        初始化岗位信息
        """
        self.post_data = [
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "id": uuid.uuid4(),
                "name": "测试工程师",
                "code": "tester",
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "id": uuid.uuid4(),
                "name": "运维工程师",
                "code": "linux",
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "id": uuid.uuid4(),
                "name": "开发工程师",
                "code": "developer",
            },
        ]
        self.save(Post, self.post_data, "岗位信息")

    def init_config(self):
        """
        初始化配置信息
        """
        self.config_data = [
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "id": uuid.uuid4(),
                "name": "主框架页-默认皮肤样式名称",
                "key": "sys.index.skinName",
                "value": "skin-blue",
                "type": "Y",
                "remark": "蓝色 skin-blue、绿色 skin-green、紫色 skin-purple、红色 skin-red、黄色 skin-yellow",
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "id": uuid.uuid4(),
                "name": "用户-账号初始密码",
                "key": "sys.user.initPassword",
                "value": "123456",
                "type": "Y",
                "remark": "初始化密码 123456",
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "id": uuid.uuid4(),
                "name": "主框架页-侧边栏主题",
                "key": "sys.index.sidebarStyle",
                "value": "theme-dark",
                "type": "Y",
                "remark": "深色主题theme-dark，浅色主题theme-light",
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "id": uuid.uuid4(),
                "name": "账号自助-验证码开关",
                "key": "sys.account.captchaEnabled",
                "value": "true",
                "type": "Y",
                "remark": "是否开启验证码功能（true开启，false关闭）",
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "id": uuid.uuid4(),
                "name": "账号自助-是否开启用户注册功能",
                "key": "sys.account.registerUser",
                "value": "false",
                "type": "Y",
                "remark": "是否开启注册用户功能（true开启，false关闭）",
            },
        ]
        self.save(Config, self.config_data, "配置信息")

    def init_menu(self):
        """
        初始化菜单表-系统管理
        """
        sys = uuid.uuid4()
        sys_user = uuid.uuid4()
        sys_role = uuid.uuid4()
        sys_menu = uuid.uuid4()
        sys_dept = uuid.uuid4()
        sys_post = uuid.uuid4()
        sys_dict = uuid.uuid4()
        sys_config = uuid.uuid4()
        sys_file = uuid.uuid4()
        sys_notice = uuid.uuid4()
        sys_log = uuid.uuid4()
        sys_whitelist = uuid.uuid4()
        self.menu_sys_data = [
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "id": sys,
                "name": "系统管理",
                "type": "M",
                "icon": "system",
                "path": "/sys",
                "component": "Layout",
                "perms": None,
                "nesting": True,
                "redirect": "noRedirect",
                "parent_id": None,
                "sort": 1,
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "id": sys_user,
                "name": "用户管理",
                "type": "C",
                "icon": "user",
                "path": "user",
                "component": "sys/user/index",
                "perms": "sys:user:list",
                "parent_id": sys,
                "sort": 1,
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "id": uuid.uuid4(),
                "name": "用户查询",
                "type": "F",
                "icon": "#",
                "perms": "sys:user:query",
                "parent_id": sys_user,
                "sort": 1,
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "id": uuid.uuid4(),
                "name": "用户新增",
                "type": "F",
                "icon": "#",
                "perms": "sys:user:add",
                "parent_id": sys_user,
                "sort": 2,
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "id": uuid.uuid4(),
                "name": "用户修改",
                "type": "F",
                "icon": "#",
                "perms": "sys:user:edit",
                "parent_id": sys_user,
                "sort": 3,
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "id": uuid.uuid4(),
                "name": "用户删除",
                "type": "F",
                "icon": "#",
                "perms": "sys:user:delete",
                "parent_id": sys_user,
                "sort": 4,
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "id": uuid.uuid4(),
                "name": "用户导入",
                "type": "F",
                "icon": "#",
                "perms": "sys:user:import",
                "parent_id": sys_user,
                "sort": 5,
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "id": uuid.uuid4(),
                "name": "用户导出",
                "type": "F",
                "icon": "#",
                "perms": "sys:user:export",
                "parent_id": sys_user,
                "sort": 6,
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "id": uuid.uuid4(),
                "name": "重置密码",
                "type": "F",
                "icon": "#",
                "perms": "sys:user:resetPwd",
                "parent_id": sys_user,
                "sort": 7,
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "id": uuid.uuid4(),
                "name": "分配角色",
                "type": "F",
                "icon": "#",
                "perms": "sys:user:authRole",
                "parent_id": sys_user,
                "sort": 8,
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "id": sys_role,
                "name": "角色管理",
                "type": "C",
                "icon": "peoples",
                "path": "role",
                "component": "sys/role/index",
                "perms": "sys:role:list",
                "parent_id": sys,
                "sort": 2,
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "id": uuid.uuid4(),
                "name": "角色查询",
                "type": "F",
                "icon": "#",
                "perms": "sys:role:query",
                "parent_id": sys_role,
                "sort": 1,
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "id": uuid.uuid4(),
                "name": "角色新增",
                "type": "F",
                "icon": "#",
                "perms": "sys:role:add",
                "parent_id": sys_role,
                "sort": 2,
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "id": uuid.uuid4(),
                "name": "角色修改",
                "type": "F",
                "icon": "#",
                "perms": "sys:role:edit",
                "parent_id": sys_role,
                "sort": 3,
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "id": uuid.uuid4(),
                "name": "角色删除",
                "type": "F",
                "icon": "#",
                "perms": "sys:role:delete",
                "parent_id": sys_role,
                "sort": 4,
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "id": uuid.uuid4(),
                "name": "角色导出",
                "type": "F",
                "icon": "#",
                "perms": "sys:role:export",
                "parent_id": sys_role,
                "sort": 5,
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "id": uuid.uuid4(),
                "name": "数据权限",
                "type": "F",
                "icon": "#",
                "perms": "sys:role:dataScope",
                "parent_id": sys_role,
                "sort": 6,
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "id": uuid.uuid4(),
                "name": "分配用户",
                "type": "F",
                "icon": "#",
                "perms": "sys:role:authUser",
                "parent_id": sys_role,
                "sort": 7,
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "id": sys_menu,
                "name": "菜单管理",
                "type": "C",
                "icon": "tree-table",
                "path": "menu",
                "component": "sys/menu/index",
                "perms": "sys:menu:list",
                "parent_id": sys,
                "sort": 3,
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "id": uuid.uuid4(),
                "name": "菜单查询",
                "type": "F",
                "icon": "#",
                "perms": "sys:menu:query",
                "parent_id": sys_menu,
                "sort": 1,
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "id": uuid.uuid4(),
                "name": "菜单新增",
                "type": "F",
                "icon": "#",
                "perms": "sys:menu:add",
                "parent_id": sys_menu,
                "sort": 2,
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "id": uuid.uuid4(),
                "name": "菜单编辑",
                "type": "F",
                "icon": "#",
                "perms": "sys:menu:edit",
                "parent_id": sys_menu,
                "sort": 3,
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "id": uuid.uuid4(),
                "name": "菜单删除",
                "type": "F",
                "icon": "#",
                "perms": "sys:menu:delete",
                "parent_id": sys_menu,
                "sort": 4,
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "id": sys_dept,
                "name": "部门管理",
                "type": "C",
                "icon": "tree",
                "path": "dept",
                "component": "sys/dept/index",
                "perms": "sys:dept:list",
                "parent_id": sys,
                "sort": 4,
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "id": uuid.uuid4(),
                "name": "部门查询",
                "type": "F",
                "icon": "#",
                "perms": "sys:dept:query",
                "parent_id": sys_dept,
                "sort": 1,
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "id": uuid.uuid4(),
                "name": "部门新增",
                "type": "F",
                "icon": "#",
                "perms": "sys:dept:add",
                "parent_id": sys_dept,
                "sort": 2,
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "id": uuid.uuid4(),
                "name": "部门编辑",
                "type": "F",
                "icon": "#",
                "perms": "sys:dept:edit",
                "parent_id": sys_dept,
                "sort": 3,
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "id": uuid.uuid4(),
                "name": "部门删除",
                "type": "F",
                "icon": "#",
                "perms": "sys:dept:delete",
                "parent_id": sys_dept,
                "sort": 4,
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "id": sys_post,
                "name": "岗位管理",
                "type": "C",
                "icon": "post",
                "path": "post",
                "component": "sys/post/index",
                "perms": "sys:post:list",
                "parent_id": sys,
                "sort": 5,
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "id": uuid.uuid4(),
                "name": "岗位查询",
                "type": "F",
                "icon": "#",
                "perms": "sys:post:query",
                "parent_id": sys_post,
                "sort": 1,
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "id": uuid.uuid4(),
                "name": "岗位新增",
                "type": "F",
                "icon": "#",
                "perms": "sys:post:add",
                "parent_id": sys_post,
                "sort": 2,
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "id": uuid.uuid4(),
                "name": "岗位编辑",
                "type": "F",
                "icon": "#",
                "perms": "sys:post:edit",
                "parent_id": sys_post,
                "sort": 3,
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "id": uuid.uuid4(),
                "name": "岗位删除",
                "type": "F",
                "icon": "#",
                "perms": "sys:post:delete",
                "parent_id": sys_post,
                "sort": 4,
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "id": uuid.uuid4(),
                "name": "岗位导出",
                "type": "F",
                "icon": "#",
                "perms": "sys:post:export",
                "parent_id": sys_post,
                "sort": 5,
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "id": sys_dict,
                "name": "字典管理",
                "type": "C",
                "icon": "dict",
                "path": "dict",
                "component": "sys/dict/index",
                "perms": "sys:dict:list",
                "parent_id": sys,
                "sort": 6,
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "id": uuid.uuid4(),
                "name": "字典查询",
                "type": "F",
                "icon": "#",
                "perms": "sys:dict:query",
                "parent_id": sys_dict,
                "sort": 1,
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "id": uuid.uuid4(),
                "name": "字典新增",
                "type": "F",
                "icon": "#",
                "perms": "sys:dict:add",
                "parent_id": sys_dict,
                "sort": 2,
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "id": uuid.uuid4(),
                "name": "字典编辑",
                "type": "F",
                "icon": "#",
                "perms": "sys:dict:edit",
                "parent_id": sys_dict,
                "sort": 3,
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "id": uuid.uuid4(),
                "name": "字典删除",
                "type": "F",
                "icon": "#",
                "perms": "sys:dict:delete",
                "parent_id": sys_dict,
                "sort": 4,
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "id": uuid.uuid4(),
                "name": "字典导出",
                "type": "F",
                "icon": "#",
                "perms": "sys:dict:export",
                "parent_id": sys_dict,
                "sort": 5,
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "id": sys_config,
                "name": "配置管理",
                "type": "C",
                "icon": "edit",
                "path": "config",
                "component": "sys/config/index",
                "perms": "sys:config:list",
                "parent_id": sys,
                "sort": 7,
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "id": uuid.uuid4(),
                "name": "配置查询",
                "type": "F",
                "icon": "#",
                "perms": "sys:config:query",
                "parent_id": sys_config,
                "sort": 1,
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "id": uuid.uuid4(),
                "name": "配置新增",
                "type": "F",
                "icon": "#",
                "perms": "sys:config:add",
                "parent_id": sys_config,
                "sort": 2,
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "id": uuid.uuid4(),
                "name": "配置编辑",
                "type": "F",
                "icon": "#",
                "perms": "sys:config:edit",
                "parent_id": sys_config,
                "sort": 3,
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "id": uuid.uuid4(),
                "name": "配置删除",
                "type": "F",
                "icon": "#",
                "perms": "sys:config:delete",
                "parent_id": sys_config,
                "sort": 4,
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "id": uuid.uuid4(),
                "name": "配置导出",
                "type": "F",
                "icon": "#",
                "perms": "sys:config:export",
                "parent_id": sys_config,
                "sort": 5,
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "id": sys_file,
                "name": "附件管理",
                "type": "C",
                "icon": "documentation",
                "path": "file",
                "component": "sys/file/index",
                "perms": "sys:file:list",
                "parent_id": sys,
                "sort": 8,
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "id": uuid.uuid4(),
                "name": "附件上传",
                "type": "F",
                "icon": "#",
                "perms": "sys:file:upload",
                "parent_id": sys_file,
                "sort": 1,
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "id": uuid.uuid4(),
                "name": "附件下载",
                "type": "F",
                "icon": "#",
                "perms": "sys:file:download",
                "parent_id": sys_file,
                "sort": 2,
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "id": uuid.uuid4(),
                "name": "附件删除",
                "type": "F",
                "icon": "#",
                "perms": "sys:file:delete",
                "parent_id": sys_file,
                "sort": 3,
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "id": sys_notice,
                "name": "公告管理",
                "type": "C",
                "icon": "message",
                "path": "notice",
                "component": "sys/notice/index",
                "perms": "sys:notice:list",
                "parent_id": sys,
                "sort": 9,
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "id": uuid.uuid4(),
                "name": "公告查询",
                "type": "F",
                "icon": "#",
                "perms": "sys:notice:query",
                "parent_id": sys_notice,
                "sort": 1,
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "id": uuid.uuid4(),
                "name": "公告新增",
                "type": "F",
                "icon": "#",
                "perms": "sys:notice:add",
                "parent_id": sys_notice,
                "sort": 2,
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "id": uuid.uuid4(),
                "name": "公告编辑",
                "type": "F",
                "icon": "#",
                "perms": "sys:notice:edit",
                "parent_id": sys_notice,
                "sort": 3,
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "id": uuid.uuid4(),
                "name": "公告删除",
                "type": "F",
                "icon": "#",
                "perms": "sys:notice:delete",
                "parent_id": sys_notice,
                "sort": 4,
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "id": sys_log,
                "name": "日志管理",
                "type": "M",
                "icon": "log",
                "path": "log",
                "component": "ParentView",
                "perms": None,
                "nesting": True,
                "redirect": "",
                "parent_id": sys,
                "sort": 10,
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "id": uuid.uuid4(),
                "name": "操作日志",
                "type": "C",
                "icon": "form",
                "path": "operlog",
                "component": "sys/operlog/index",
                "perms": "sys:operlog:list",
                "parent_id": sys_log,
                "sort": 1,
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "id": uuid.uuid4(),
                "name": "登录日志",
                "type": "C",
                "icon": "form",
                "path": "loginlog",
                "component": "sys/loginlog/index",
                "perms": "sys:loginlog:list",
                "parent_id": sys_log,
                "sort": 2,
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "id": sys_whitelist,
                "name": "白名单管理",
                "type": "C",
                "icon": "whitelist",
                "path": "whitelist",
                "component": "sys/whitelist/index",
                "perms": "sys:whitelist:list",
                "parent_id": sys,
                "sort": 11,
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "id": uuid.uuid4(),
                "name": "白名单查询",
                "type": "F",
                "icon": "#",
                "perms": "sys:whitelist:query",
                "parent_id": sys_whitelist,
                "sort": 1,
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "id": uuid.uuid4(),
                "name": "白名单新增",
                "type": "F",
                "icon": "#",
                "perms": "sys:whitelist:add",
                "parent_id": sys_whitelist,
                "sort": 2,
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "id": uuid.uuid4(),
                "name": "白名单编辑",
                "type": "F",
                "icon": "#",
                "perms": "sys:whitelist:edit",
                "parent_id": sys_whitelist,
                "sort": 3,
            },
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "id": uuid.uuid4(),
                "name": "白名单删除",
                "type": "F",
                "icon": "#",
                "perms": "sys:whitelist:delete",
                "parent_id": sys_whitelist,
                "sort": 4,
            },
        ]
        self.save(Menu, self.menu_sys_data, "菜单表")

    def init_role(self):
        """
        初始化角色表
        """
        data = [
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": self.creator_id,
                "id": self.superadmin_role_id,
                "name": "超级管理员",
                "key": "superadmin",
                "admin": True,
                "data_scope": 0,
                "sort": 1,
                "menu": [],
                "remark": "超级管理员",
            }
        ]
        self.save(Role, data, "角色表")

    def init_users(self):
        """
        初始化用户表
        """
        data = [
            {
                "dept_belong_id": self.dept_belong_id,
                "update_time": datetime.now(),
                "create_time": datetime.now(),
                "creator_id": None,
                "id": self.creator_id,
                "username": "superadmin",
                "password": "pbkdf2_sha256$600000$b3iFM9uXK4YlDg4qP3tn5J$W9ck9Pt5z4FtFR7BLx56dl/RSVDi+eRn2EPdjc8z66E=",
                "first_name": "",
                "last_name": "",
                "is_superuser": True,
                "is_staff": True,
                "is_active": True,
                "email": "superadmin@yuantest.com",
                "mobile": "15191571081",
                "name": "超级管理员",
                "gender": 1,
                "dept_id": self.dept_belong_id,
            }
        ]
        self.save(User, data, "用户表")

    def run(self):
        self.init_dict()
        self.init_dept()
        self.init_post()
        self.init_config()
        self.init_menu()
        self.init_role()
        self.init_users()


def main(reset=False):
    Init(reset).run()
    pass


if __name__ == "__main__":
    main()
